package org.cwnuit.course.dao;

import java.sql.SQLException;
import java.util.List;

import org.cwnuit.course.domain.Classes;
import org.cwnuit.course.util.IbatisSqlConfig;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * 班级管理DAO
 * @author john
 */
public class ClassesDAO{
	
	/**
	 * 根据班级ID获取班级信息
	 * @param classid
	 * @return
	 */
	public Classes getClasses(Integer classid) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		Classes classes = null;
		try {
			classes = (Classes) sqlMap.queryForObject("Classes.getClasses",classid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return classes;
	}

	/**
	 * 获取全部班级信息
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Classes> listClasses() {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		List<Classes> classesList = null;
		try {
			classesList = (List<Classes>) sqlMap.queryForList("Classes.listClasses");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return classesList;
	}
	
	/**
	 * 添加班级信息
	 * @param Classes
	 * @return
	 */
	public boolean insertClasses(Classes classes) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.insert("Classes.insertClasses", classes);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	/**
	 * 更新班级信息
	 * @param Classes* @return
	 */
	public boolean updateClasses(Classes classes) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.update("Classes.updateClasses",classes);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	/**
	 * 删除班级信息
	 * @param classid
	 * @return
	 */
	public boolean deleteClasses(Classes classes) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.delete("Classes.deleteClasses", classes);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
}
